<template>
  <div>
    <el-tag>印刷</el-tag>
    <el-checkbox @change="clickToChange()">需要</el-checkbox>
    <div class="content">
      <el-radio v-model="printf.type" label="普通印刷" :disabled="disable">普通印刷</el-radio>
      <el-radio v-model="printf.type" label="UV印刷" :disabled="disable">UV印刷</el-radio>
    </div>
    <div class="content">
      <template v-if="printf.type === '普通印刷'">
        <el-checkbox :disabled="disable" @change="disableChange('sise_disable')"></el-checkbox>
        <span>四色:</span>
        <el-select v-model="printf.sise" placeholder="请选择" size="small" :disabled="sise_disable">
          <el-option v-for="item in option.printf_option_bu" :key="item" :label="item" :value="item"></el-option>
        </el-select>
        <el-checkbox :disabled="disable" @change="disableChange('zhuanse_disable')"></el-checkbox>
        <span>专色:</span>
        <el-select v-model="printf.zhuanse" placeholder="请选择" size="small" :disabled="zhuanse_disable">
          <el-option v-for="item in option.printf_option_bu" :key="item" :label="item" :value="item"></el-option>
        </el-select>
        <el-input v-model="printf.zhuan_se_num" placeholder="请输入数量" size="small" :disabled="zhuanse_disable"></el-input>
        <br/>
        <el-checkbox :disabled="disable" @change="disableChange('yingyou_disable')"></el-checkbox>
        <span>印油:</span>
        <el-select v-model="printf.yingyou" placeholder="请选择" size="small" :disabled="yingyou_disable" class="length">
          <el-option v-for="item in option.printf_option_bu" :key="item" :label="item" :value="item"></el-option>
        </el-select>
      </template>
      <template v-else>
        <el-checkbox :disabled="disable" @change="disableChange('sise_disable')"></el-checkbox>
        <span>四色:</span>
        <el-select v-model="printf.sise" placeholder="请选择" size="small" :disabled="sise_disable">
          <el-option v-for="item in option.printf_option" :key="item" :label="item" :value="item"></el-option>
        </el-select>
        <el-checkbox :disabled="disable" @change="disableChange('zhuanse_disable')"></el-checkbox>
        <span>专色:</span>
        <el-select v-model="printf.zhuanse" placeholder="请选择" size="small" :disabled="zhuanse_disable">
          <el-option v-for="item in option.printf_option" :key="item" :label="item" :value="item"></el-option>
        </el-select>
        <br/>
        <el-checkbox :disabled="disable" @change="disableChange('mosha_disable')"></el-checkbox>
        <span>磨砂:</span>
        <el-select v-model="printf.mosha" placeholder="请选择" size="small" :disabled="mosha_disable" class="length">
          <el-option v-for="item in option.printf_option" :key="item" :label="item" :value="item"></el-option>
        </el-select>
        <el-checkbox :disabled="disable" @change="disableChange('baimo_disable')"></el-checkbox>
        <span>白墨:</span>
        <el-select v-model="printf.baimo" placeholder="请选择" size="small" :disabled="baimo_disable" class="length">
          <el-option v-for="item in option.printf_option" :key="item" :label="item" :value="item"></el-option>
        </el-select>
      </template>
      <br/>
      <span>额外费用:</span>
      <el-input v-model="printf.e_wai" placeholder="请输入费用" size="small" class = "length" :disabled="disable"></el-input>
  </div>
    <template v-if="getRole()">
    <el-tag type="warning" class="cost">四色成本: {{computeCost()[0]}}</el-tag>
    <el-tag type="warning" class="cost">专色成本: {{computeCost()[1]}}</el-tag>
    <el-tag type="warning" class="cost" v-if="printf.type === '普通印刷'">印油成本: {{computeCost()[2]}}</el-tag>
    <el-tag type="warning" class="cost" v-if="printf.type === 'UV印刷'">磨砂成本: {{computeCost()[2]}}</el-tag>
    <el-tag type="warning" class="cost" v-if="printf.type === 'UV印刷'">白墨成本: {{computeCost()[3]}}</el-tag>
    </template>
  </div>
</template>

<script>
export default {
  name: 'Yinshua',
  props: ['Q', 'x', 'y', 'confirm'],
  data () {
    return {
      disable: true,
      sise_disable: true,
      zhuanse_disable: true,
      baimo_disable: true,
      mosha_disable: true,
      yingyou_disable: true,
      printf: {
        type: '普通印刷',
        sise: '',
        zhuanse: '',
        yingyou: '',
        baimo: '',
        mosha: '',
        zhuan_se_num: 1,
        e_wai: 0,
        q: 0
      },
      option: {
        printf_option: ['六开', '四开', '对开'],
        printf_option_bu: ['六开', '四开', '对开', '全开']
      }
    }
  },
  methods: {
    computeCost () {
      let Q = parseInt(this.Q)
      let n = parseInt(this.printf.zhuan_se_num)
      let m = this.x * this.y * 0.7 * ((Q - 1000) / 1000) / Math.pow(10, 6)
      if (this.printf.type === '普通印刷') {
        let siSeCost
        let siSeCostStr
        let zhuanSeCost
        let zhuanSeCostStr
        let yinYouCost
        let yinYouCostStr
        // 计算普通印刷四色成本
        switch (this.printf.sise) {
          case '六开':
            siSeCost = Q <= 1000 ? 160 : 160 + 30 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? `160 (Q ≤ 1000)` : `160 + 30 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          case '四开':
            siSeCost = Q <= 1000 ? 260 : 260 + 40 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? '260 (Q ≤ 1000)' : `260 + 40 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          case '对开':
            siSeCost = Q <= 1000 ? 400 : 400 + 50 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? '400 (Q ≤ 1000)' : `400 + 50 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          case '全开':
            siSeCost = Q <= 5000 ? 1100 + 100 * ((Q - 1000) / 1000) : 0.3 * (Q - 1000)
            siSeCostStr = Q <= 5000 ? `1100 + 100 × ((${Q} - 1000) / 1000) = ${siSeCost}` : `0.3 × (${Q} - 1000) = ${siSeCost}`
            break
          default:
            siSeCost = 0
            siSeCostStr = '0'
        }
        // 计算普通印刷专色成本
        switch (this.printf.zhuanse) {
          case '六开':
            zhuanSeCost = Q <= 1000 ? 120 * n : 120 * n + 30 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? `120 × ${n} = ${zhuanSeCost}`
              : `120 × ${n} + 30 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          case '四开':
            zhuanSeCost = Q <= 1000 ? 260 + 100 * (n - 1) : 260 + 100 * (n - 1) + 50 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? `260 + 100 × (${n} - 1) = ${zhuanSeCost}`
              : `260 + 100 × (${n} - 1) + 50 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          case '对开':
            zhuanSeCost = Q <= 1000 ? 400 + 100 * (n - 1) : 400 + 100 * (n - 1) + 50 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? `400 + 100 × (${n} - 1) = ${zhuanSeCost}`
              : `400 + 100 × (${n} - 1) + 50 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          default:
            zhuanSeCostStr = '0'
            zhuanSeCost = 0
            break
        }
        // 计算普通印刷印油成本
        switch (this.printf.yingyou) {
          case '六开':
            yinYouCost = Q <= 1000 ? 80 : 80 + 30 * ((Q - 1000) / 1000)
            yinYouCostStr = Q <= 1000 ? '80 (Q ≤ 1000)' : `80 + 30 × ((${Q} - 1000) / 1000) = ${yinYouCost}`
            break
          case '四开':
            yinYouCost = Q <= 1000 ? 150 : 150 + 50 * ((Q - 1000) / 1000)
            yinYouCostStr = Q <= 1000 ? '150 (Q ≤ 1000)' : `150 + 50 × ((${Q} - 1000) / 1000) = ${yinYouCost}`
            break
          case '对开':
            yinYouCost = Q <= 1000 ? 250 : 250 + 100 * ((Q - 1000) / 1000)
            yinYouCostStr = Q <= 1000 ? '250 (Q ≤ 1000)' : `250 + 100 × ((${Q} - 1000) / 1000) = ${yinYouCost}`
            break
          case '全开':
            yinYouCost = 200 + 0.12 * Q
            yinYouCostStr = `200 + 0.12 × ${Q} = ${yinYouCost}`
            break
          default:
            yinYouCost = 0
            yinYouCostStr = '0'
        }
        return [siSeCostStr, zhuanSeCostStr, yinYouCostStr]
      } else {
        let siSeCost
        let siSeCostStr
        let moShaCost
        let moShaCostStr
        let baiMoCost
        let baiMoCostStr
        let zhuanSeCost
        let zhuanSeCostStr
        // 计算uv印刷四色成本
        switch (this.printf.sise) {
          case '六开':
            siSeCost = Q <= 1000 ? 500 : 500 + 100 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? '500 (Q ≤ 1000)' : `500 + 100 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          case '四开':
            siSeCost = Q <= 1000 ? 800 : 800 + 100 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? '800 (Q ≤ 1000)' : `800 + 100 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          case '对开':
            siSeCost = Q <= 1000 ? 1200 : 1200 + 150 * ((Q - 1000) / 1000)
            siSeCostStr = Q <= 1000 ? '1200 (Q ≤ 1000)' : `1200 + 150 × ((${Q} - 1000) / 1000) = ${siSeCost}`
            break
          default:
            siSeCost = 0
            siSeCostStr = '0'
        }
        // 计算uv印刷磨砂成本
        switch (this.printf.mosha) {
          case '六开':
            moShaCost = Q <= 1000 ? 200 : 200 + 100 * ((Q - 1000) / 1000)
            moShaCostStr = Q <= 1000 ? '200 (Q ≤ 1000)' : `200 + 100 × ((${Q} - 1000) / 1000) = ${moShaCost}`
            break
          case '四开':
            moShaCost = Q <= 1000 || m <= 300 ? 300 : m
            moShaCostStr = Q <= 1000 || m <= 300 ? `300 [${this.x} × ${this.y} × 0.7 × ((${Q} - 1000) / 1000) × (10^-6) ≤ 300]`
              : `${this.x} × ${this.y} × 0.7 × ((${Q} - 1000) / 1000) × (10^-6) = ${moShaCost}`
            break
          case '对开':
            moShaCost = Q <= 1000 || m <= 400 ? 400 : m
            moShaCostStr = Q <= 1000 || m <= 400 ? `400 [${this.x} × ${this.y} × 0.7 × ((${Q} - 1000) / 1000) × (10^-6) ≤ 400]`
              : `${this.x} × ${this.y} × 0.7 × ((${Q} - 1000) / 1000) × (10^-6) = ${moShaCost}`
            break
          default:
            moShaCost = 0
            moShaCostStr = '0'
            break
        }
        // 计算uv印刷白墨成本
        switch (this.printf.baimo) {
          case '六开':
            baiMoCost = Q <= 1000 ? 100 : 100 + 50 * ((Q - 1000) / 1000)
            baiMoCostStr = Q <= 1000 ? '100 (Q ≤ 1000)' : `100 + 50 × ((${Q} - 1000) / 1000) = ${baiMoCost}`
            break
          case '四开':
            baiMoCost = Q <= 1000 ? 100 : 100 + 50 * ((Q - 1000) / 1000)
            baiMoCostStr = Q <= 1000 ? '100 (Q ≤ 1000)' : `100 + 50 × ((${Q} - 1000) / 1000) = ${baiMoCost}`
            break
          case '对开':
            baiMoCost = Q <= 1000 ? 200 : 200 + 100 * ((Q - 1000) / 1000)
            baiMoCostStr = Q <= 1000 ? '200 (Q ≤ 1000)' : `200 + 100 × ((${Q} - 1000) / 1000) = ${baiMoCost}`
            break
          default:
            baiMoCost = 0
            baiMoCostStr = '0'
        }
        // 计算uv印刷专色成本
        switch (this.printf.zhuanse) {
          case '六开':
            zhuanSeCost = Q <= 1000 ? 100 : 100 + 50 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? '100 (Q ≤ 1000)' : `100 + 50 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          case '四开':
            zhuanSeCost = Q <= 1000 ? 100 : 100 + 50 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? '100 (Q ≤ 1000)' : `100 + 50 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          case '对开':
            zhuanSeCost = Q <= 1000 ? 200 : 200 + 100 * ((Q - 1000) / 1000)
            zhuanSeCostStr = Q <= 1000 ? '200 (Q ≤ 1000)' : `200 + 100 × ((${Q} - 1000) / 1000) = ${zhuanSeCost}`
            break
          default:
            zhuanSeCost = 0
            zhuanSeCostStr = '0'
        }
        return [siSeCostStr, zhuanSeCostStr, moShaCostStr, baiMoCostStr]
      }
    },
    clickToFin () {
      if (!this.disable) this.$emit('transferToFather', 'yinshua', this.printf)
    },
    clickToChange () {
      this.disable = !this.disable
    },
    getRole () {
      return sessionStorage.getItem('roleType') === '1'
    },
    disableChange (name) {
      this[name] = !this[name]
      name = name.split('_')[0]
      console.log(name)
      let printList = ['sise', 'zhuanse', 'yingyou', 'mosha', 'baimo']
      for (let i = 0; i < printList.length; i++) {
        if (this.printf[printList[i]]) this.printf[name] = this.printf[printList[i]]
      }
    }
  },
  watch: {
    confirm (nV, oV) {
      if (nV !== oV) this.clickToFin()
    }
  }
}
</script>

<style scoped>
.content{
  margin: 10px 0;
}

.el-select{
  width: 100px;
  margin-right: 10px;
}

.el-input{
  width: 100px;
  margin-right: 10px;
}

.el-checkbox{
  margin-right: 5px!important;
}

.length{
  margin-top: 10px;
}

</style>
